package org.ihelpuoo.weboo.bean;

import org.ihelpuoo.lang.StringUtils;
import org.ihelpuoo.weboo.DataChecker;

/**
 * <b>ActionParamBean class:</b>
 * <hr color=grey size=1>
 *
 *
 *
 * @author zozoh  created @ 2006
 *
 */
public class ParamBean
{

	public ParamBean()
	{
		super();
	}

	private String		alias;
	private String		checker;
	private String		setting;
	private String		comment;
	private boolean		required;
	private String		name;

	private DataChecker	_checker;

	public boolean isRequired()
	{
		return required;
	}

	public void setRequired(boolean required)
	{
		this.required = required;
	}

	public String getAlias()
	{
		return alias;
	}

	public String getAliasName()
	{
		return null == alias ? name : alias;
	}

	public void setAlias(String alias)
	{
		this.alias = alias;
	}

	public String getChecker()
	{
		return checker;
	}

	public void setChecker(String type)
	{
		this.checker = StringUtils.trim(type);
		this._checker = null;
	}

	public boolean isValid(String v)
	{
		DataChecker dc = this.getCheckerInstance();
		if (null == dc)
			return true;
		return dc.isValid(v);
	}

	private DataChecker getCheckerInstance()
	{
		if (null == this.checker)
			return null;
		if (null == this._checker)
		{
			synchronized (this)
			{
				if (null == this._checker)
				{
					try
					{
						this._checker = (DataChecker)Class.forName(checker).newInstance();
					}
					catch (Exception e)
					{
						throw new RuntimeException(e);
					}
					this._checker.setSetting(setting);
				}
			}
		}
		return this._checker;
	}

	public String getSetting()
	{
		return setting;
	}

	public void setSetting(String checkerSetting)
	{
		this.setting = StringUtils.trim(checkerSetting);
	}

	public String getComment()
	{
		return comment;
	}

	public void setComment(String comment)
	{
		this.comment = StringUtils.trim(comment);
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = StringUtils.trim(name);
	}

}
